package com.api.shopapi.service.impl;

import com.api.shopapi.entity.NurseAide;
import com.api.shopapi.entity.User;
import com.api.shopapi.entity.dto.NurseAideDTO;
import com.api.shopapi.entity.dto.NurseDTO;
import com.api.shopapi.mapper.NurseAideMapper;
import com.api.shopapi.service.NurseAideService;
import com.api.shopapi.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("NurseAideServiceImplOne")
public class NurseAideServiceImpl implements NurseAideService {

    @Autowired
    private NurseAideMapper nurseAideMapper;

    @Autowired
    @Qualifier("UserServiceImplOne")
    private UserService userService;

    @Override
    public List<NurseAideDTO> getList(String institutionCode) {
        return nurseAideMapper.getList(institutionCode);
    }

    @Override
    public int insert(NurseAide nurseAide) {
        return nurseAideMapper.insert(nurseAide);
    }

    @Override
    @Transactional
    public int updateByNurseAideCode(User user,NurseAide nurseAide) {
        userService.update(user);
        return nurseAideMapper.updateByNurseAideCode(nurseAide);
    }

    @Override
    public int deleteByNurseAideCode(String nurseAideCode) {
        return nurseAideMapper.deleteByNurseAideCode(nurseAideCode);
    }

    @Override
    public NurseAide getByNurseAideCode(String nurseAideCode) {
        return nurseAideMapper.getByNurseAideCode(nurseAideCode);
    }

    @Override
    @Transactional
    public int regInsert(User user, NurseAide nurseAide) {
        userService.insert(user);
        return nurseAideMapper.insert(nurseAide);
    }

    @Override
    public NurseAide getByUserCode(String userCode) {
        return nurseAideMapper.getByUserCode(userCode);
    }

    @Override
    public
    PageInfo<NurseAideDTO> getPageList(int pageIndex, int pageSize, String institutionCode, String name, int status){
        PageHelper.startPage(pageIndex, pageSize);
        List<NurseAideDTO> nurseDTOList = nurseAideMapper.getPageList(institutionCode,name,status);
        PageInfo<NurseAideDTO> pageInfo = new PageInfo<>(nurseDTOList);
        return pageInfo;
    }


    @Override
    public
    PageInfo<NurseAideDTO> pageByGovCode(int pageIndex, int pageSize, String governmentCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<NurseAideDTO> nurseDTOList = nurseAideMapper.listByGovCode(governmentCode);
        PageInfo<NurseAideDTO> pageInfo = new PageInfo<>(nurseDTOList);
        return pageInfo;
    }

    @Override
    public
    PageInfo<NurseAide> pageByGovCodeInsCode(int pageIndex, int pageSize, String governmentCode,String institutionCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<NurseAide> nurseDTOList = nurseAideMapper.listByGovCodeInsCode(governmentCode,institutionCode);
        PageInfo<NurseAide> pageInfo = new PageInfo<>(nurseDTOList);
        return pageInfo;
    }

    @Override
    public
    List<NurseAideDTO> listByGovCode(String governmentCode){
        return nurseAideMapper.listByGovCode(governmentCode);
    }

    @Override
    public
    List<NurseAideDTO> listByInsCode(String institutionCode){
        return nurseAideMapper.listByInsCode(institutionCode);
    }


}
